#include "threadPool.hpp"

pthread_mutex_t td = PTHREAD_MUTEX_INITIALIZER;

void c1(void)
{
    pthread_mutex_lock(&td);
    std::cout << 1 << std::endl;
    std::cout << "success :: " << pthread_self() << std::endl;
    pthread_mutex_unlock(&td);
}

void c2(void)
{
    pthread_mutex_lock(&td);
    std::cout << 2 << std::endl;
    std::cout << "success :: " << pthread_self() << std::endl;
    pthread_mutex_unlock(&td);
}

void c3(void)
{
    pthread_mutex_lock(&td);
    std::cout << 3 << std::endl;
    std::cout << "success :: " << pthread_self() << std::endl;
    pthread_mutex_unlock(&td);
}

void c4(void)
{
    pthread_mutex_lock(&td);
    std::cout << 4 << std::endl;
    std::cout << "success :: " << pthread_self() << std::endl;
    pthread_mutex_unlock(&td);
}

int main()
{
    threadPool<void()> t(5);
    t.push(std::function<void()>(c1));
    //sleep(5);
    t.push(std::function<void()>(c2));
    //sleep(5);
    t.push(std::function<void()>(c3));
    //sleep(5);
    t.push(std::function<void()>(c4));

    sleep(10);
    return 0;
}